from flask import Blueprint, render_template, session, url_for,request
from werkzeug.utils import redirect

user=Blueprint('user',__name__, url_prefix="/user")    # 蓝图使用方法，参数里给定文件名，还可以给定url前缀

@user.route('/loginForm')   # 使用user的路由配置
def loginForm():
    return render_template("login.html")

@user.route('/login',methods=['POST','GET'])
def login():
    if request.method=='POST':
        nm=request.form['nm']
        pwd=request.form['pwd']
        if nm=='cao' and pwd=='123':
            session['username']=nm
            print(session['username'])
            return redirect(url_for('index'))
        else:
            return 'the username or userpwd does not match!'